package www.houdoudou.com.parent;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

public class ParentManagerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		//super.doPost(req, resp);
		      req.setCharacterEncoding("UTF-8"); 
		    resp.setCharacterEncoding("UTF-8");
	     //   resp.setContentType("text/html;charset=utf-8");   
	     //   resp.setHeader("Cache-Control","no-cache");  
	       
	        PrintWriter print=resp.getWriter();  
	       
	        String jsonData=req.getParameter("jsonData");
	        String PostCode=req.getParameter("PostCode");
	        
	       /* String newStr = new String(jsonData.getBytes("ISO-8859-1"), "gb2312");  
	        System.out.println("-------------"+newStr);
	        newStr=new String(jsonData.getBytes("ISO-8859-1"),"utf8");
	        System.out.println("-------------"+newStr);
	        newStr=new String(jsonData.getBytes("ISO-8859-1"),"GBK");
	        System.out.println("-------------"+newStr); */
	        int postCode=Integer.parseInt(PostCode);
	        System.out.println("there is requst in ParentManagerServlet"+PostCode+jsonData);
	        switch(postCode){
	        case 1:  {  //1验证管理员是否注册，成功 返回e参数，失败返回失败原因
	        	      JSONObject temp=  ParentManager.loginCheck(jsonData);
	    	          print.println( temp.toString()); 
	    	          System.out.println("data back to app----"+temp);
	    	          break;} 
	        case 2:  {  //母公司管理员先关增删改查
      	      JSONObject temp= new ParentManager().managerManage(jsonData);
  	          print.println( temp.toString()); 
  	           System.out.println("data back to app----"+temp);
  	          break;} 
	        case 3:  {  //母公司区域经理 对业主的增删改查
	      	      JSONObject temp= ParentManageOwner.manageOwner(jsonData);
	  	          print.println( temp.toString()); 
	  	           System.out.println("data back to app----"+temp);
	  	          break;} 
	        case 4:  {  //母公司区域经理 对机器的增删改查
	      	      JSONObject temp= ParentManageMachine.manageMachine(jsonData);
	  	          print.println( temp.toString()); 
	  	           System.out.println("data back to app----"+temp);
	  	          break;} 
	      
       }
	        
	        print.close();  
		
	}
	
	
	
}
